package de.hauschild.gmltracer.gml.impl.array;

import de.hauschild.gmltracer.gml.Environment;
import de.hauschild.gmltracer.gml.Token;
import de.hauschild.gmltracer.gml.TokenStack;
import de.hauschild.gmltracer.gml.impl.AbstractToken;
import de.hauschild.gmltracer.gml.impl.value.integer.IntegerToken;

/**
 * Pops a {@link ArrayToken} and a {@link IntegerToken} from the
 * {@link TokenStack} and pushes the specified element out the array to the
 * stack.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
public class ArrayGetToken extends AbstractToken {

  @SuppressWarnings("boxing")
  @Override
  public void evaluate(final Environment environment, final TokenStack tokenStack) {
    final IntegerToken i = tokenStack.pop(IntegerToken.class);
    final ArrayToken array = tokenStack.pop(ArrayToken.class);

    final Token token = array.get(i.getValue());
    tokenStack.push(token);
  }

  @Override
  public String toString() {
    return "get"; //$NON-NLS-1$
  }
}
